package com.itheima.reggie.controller;

import com.itheima.reggie.comon.ResultInfo;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    //查询套餐
    @GetMapping("/list")
    @Cacheable(value = "setmeal", key = "#categoryId+'_'+#status")
    public ResultInfo<List<Setmeal>> findSetmeal(Long categoryId, Integer status) {
        List<Setmeal> setmealList = setmealService.findSetmeal(categoryId, status);
        return ResultInfo.success(setmealList);
    }

    //点击套餐查看里面的菜品
    @GetMapping("/dish/{id}")
    @Cacheable(value = "dishInSetmeal", key = "#id")
    public ResultInfo<List<Dish>> findDish(@PathVariable("id") Long id) {
        //调用service
        List<Dish> dishList = setmealService.findDish(id);
        return ResultInfo.success(dishList);
    }
}
